package com.eastfair.common.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.eastfair.annotation.model.EchoVO;
import com.eastfair.core.base.entity.Entity;
import com.eastfair.database.mybatis.typehandler.M9EncryptHandler;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import static com.baomidou.mybatisplus.annotation.SqlCondition.LIKE;
import static com.eastfair.core.utils.DateUtils.DEFAULT_DATE_TIME_FORMAT;

/**
 * <p>
 * 实体类
 * 服务商对外授权码与用户关系
 * </p>
 *
 * @author dqq
 * @since 2023-02-14
 */
@Data
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName(value = "common_auth_code_user",autoResultMap = true)
@ApiModel(value = "AuthCodeUser", description = "服务商对外授权码与用户关系")
@AllArgsConstructor
public class AuthCodeUser extends Entity<Long> implements EchoVO {

    private static final long serialVersionUID = 1L;
    @TableField(exist = false)
    private Map<String, Object> echoMap = new HashMap<>();
    /**
     * 是否启用：1是；0否
     */
    @ApiModelProperty(value = "是否启用：1是；0否")
    @TableField(value = "is_enabled")
    @Excel(name = "是否启用：1是；0否")
    private Integer isEnabled;

    /**
     * 是否删除：1是；0否
     */
    @ApiModelProperty(value = "是否删除：1是；0否")
    @TableField(value = "is_deleted")
    @Excel(name = "是否删除：1是；0否")
    private Integer isDeleted;

    /**
     * 项目id
     */
    @ApiModelProperty(value = "项目id")
    @TableField(value = "project_id")
    @Excel(name = "项目id")
    private Long projectId;

    /**
     * 子系统id
     */
    @ApiModelProperty(value = "子系统id")
    @TableField(value = "subsystem_id")
    @Excel(name = "子系统id")
    private Long subsystemId;

    /**
     * 租户id
     */
    @ApiModelProperty(value = "租户id")
    @TableField(value = "tenant_id")
    @Excel(name = "租户id")
    private Long tenantId;

    /**
     * 授权码
     */
    @ApiModelProperty(value = "授权码")
    @Size(max = 64, message = "授权码长度不能超过64")
    @TableField(value = "auth_code", condition = LIKE)
    @Excel(name = "授权码")
    private String authCode;

    /**
     * 授权用户唯一标识
     */
    @ApiModelProperty(value = "授权用户唯一标识")
    @Size(max = 200, message = "授权用户唯一标识长度不能超过200")
    @TableField(value = "auth_user_id", condition = LIKE)
    @Excel(name = "授权用户唯一标识")
    private String authUserId;

    /**
     * 用户昵称
     */
    @ApiModelProperty(value = "用户昵称")
    @Size(max = 200, message = "用户昵称长度不能超过200")
    @TableField(value = "auth_nick_name", condition = LIKE)
    @Excel(name = "用户昵称")
    private String authNickName;

    /**
     * 用户姓名
     */
    @ApiModelProperty(value = "用户姓名")
    @Size(max = 200, message = "用户姓名长度不能超过200")
    @TableField(value = "auth_user_name", condition = LIKE)
    @Excel(name = "用户姓名")
    private String authUserName;

    /**
     * 用户手机号
     */
    @ApiModelProperty(value = "用户手机号")
    @Size(max = 20, message = "用户手机号长度不能超过20")
    @TableField(value = "phone", condition = LIKE,typeHandler = M9EncryptHandler.class)
    @Excel(name = "用户手机号")
    private String phone;

    /**
     * 上次登录时间
     */
    @ApiModelProperty(value = "上次登录时间")
    @TableField(value = "last_login_time")
    @Excel(name = "上次登录时间", format = DEFAULT_DATE_TIME_FORMAT, width = 20)
    private LocalDateTime lastLoginTime;


    @Builder
    public AuthCodeUser(Long id, Long createdBy, LocalDateTime createTime, Long updatedBy, LocalDateTime updateTime, 
                    Integer isEnabled, Integer isDeleted, Long projectId, Long subsystemId, Long tenantId, 
                    String authCode, String authUserId, String authNickName, String authUserName, String phone, LocalDateTime lastLoginTime) {
        this.id = id;
        this.createdBy = createdBy;
        this.createTime = createTime;
        this.updatedBy = updatedBy;
        this.updateTime = updateTime;
        this.isEnabled = isEnabled;
        this.isDeleted = isDeleted;
        this.projectId = projectId;
        this.subsystemId = subsystemId;
        this.tenantId = tenantId;
        this.authCode = authCode;
        this.authUserId = authUserId;
        this.authNickName = authNickName;
        this.authUserName = authUserName;
        this.phone = phone;
        this.lastLoginTime = lastLoginTime;
    }

}
